package com.yueqian.sign;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.yueqian.sign.model.Classes;

import java.util.List;

public class MyAdapter<T> extends BaseAdapter {
    protected List<T> list;
    protected Context context;
    protected T item;

    public interface AdapterListener {
        View bind(int position, View convertView, ViewGroup parent);
    }

    private AdapterListener adapterListener;

    public void setAdapterListener(AdapterListener adapterListener) {
        this.adapterListener = adapterListener;
    }

    public MyAdapter(Context context, List<T> list) {
        this.context = context;
        this.list = list;
        //Log.i("MyAdapter", "MyAdapter");
    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        //Log.i("getView", "getView");
        if (adapterListener != null) {
           // Log.i("adapterListener", "adapterListener");
            convertView = adapterListener.bind(position, convertView, parent);
        }
        //Log.i("convertView", convertView.toString());

        return convertView;
    }

    public View setContentView(int id) {
        return LayoutInflater.from(context).inflate(id, null);
    }
}
